package cn.itcast.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import cn.itcast.myapplication.R;
import cn.itcast.myapplication.databinding.ActivityMyDataBindingBinding;
import cn.itcast.myapplication.viewemodel.MyViewModel;
import cn.itcast.myapplication.viewemodel.ViewModelWithLiveData;


/**
*
* 用法 定义数据实体、DAO 和数据库对象后,创建数据库实例：
*
* */


public class MyDataBinding extends AppCompatActivity {

    MyViewModel myViewModel;

    ActivityMyDataBindingBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.activity_my_data_binding);//有下面这个工具这一行代码就可以不用了
        // 数据绑定工具

        binding=DataBindingUtil.setContentView(this,R.layout.activity_my_data_binding);

        myViewModel=new ViewModelProvider(this).get(MyViewModel.class);

        binding.setData(myViewModel);//设置Data的数据为ViewModel

        binding.setLifecycleOwner(this);


    }
}